import { Avatar, message, Switch } from 'antd';
import React from 'react';
import { changeStatus } from '../service';

const chageCheck = async (id: any) => {
  const res = await changeStatus(id);
  if (res.status !== undefined) {
    message.error('操作失败');
    return;
  }
  message.success('操作成功');
};

export const columns: any[] = [
  {
    title: '头像',
    key: 'avatar_url',
    dataIndex: 'avatar_url',
    hideInSearch: true,
    search: false,
    width: 200,
    render: (record: any) => <Avatar src={record} />,
  },
  {
    title: '昵称',
    key: 'name',
    dataIndex: 'name',
    hideInSearch: false,
    valueType: 'datetime',
    width: 200,
  },
  // {
  //   title: '邮箱',
  //   key: 'email',
  //   dataIndex: 'email',
  //   hideInSearch: false,
  // },
  {
    title: '手机号',
    key: 'phone',
    dataIndex: 'phone',
    hideInSearch: false,
    width: 200,
  },
  {
    title: '是否锁定',
    key: 'is_locked',
    dataIndex: 'is_locked',
    hideInSearch: true,
    type: 'select',
    width: 200,
    valueEnum: {
      0: '锁定',
      1: '未锁定',
    },
    render: (_: any, record: any) => (
      <Switch
        checkedChildren="锁定"
        unCheckedChildren="正常"
        defaultChecked={record.is_locked}
        onChange={() => chageCheck(record.id)}
      />
    ),
  },
  {
    title: '创建时间',
    key: 'showTime',
    dataIndex: 'created_at',
    search: false,
    width: 200,
  },
  {
    title: '更新时间',
    key: 'updated_at',
    dataIndex: 'updated_at',
    search: false,
    width: 200,
  },
  {
    title: '开始时间',
    key: 'showTime',
    dataIndex: 'created_at',
    valueType: 'dateTime',
    hideInTable: true,
    type: 'date',
  },
];
